/**
 * Created by Administrator on 2017/10/7/007.
 */
public class MyArrayList<T> {
    //int size = 0;
    public static final int math = 916;
    T [] arr=(T [])new  Object [math];
    //Object[] data = new Object[math];

    public void add(int index,T o) {
        int a = arr.length;
        for (int i = arr.length - 1; i >= index; i--) {
            arr[i + 1] = arr[i];
        }
        arr[index] = o;
        a++;
    }
    public boolean add(T o){
        boolean a = false;
        for (int i = 0;i < arr.length;i++){
            if (arr[i] == null){
                arr[i] = o;
                a = true;
                break;
            }
        }
        return a;
    }
    public boolean isEmpty() {
        return arr.length == 0;
    }

    public boolean contains(T o) {
        for (int i = 0; i < arr.length; i++) {
            if (o.equals(arr[i])) {
                return true;
            }
        }
        return false;
    }

    public Object get(int index) {

        return arr[index];
    }

    public int indexOf(T o) {
        for (int i = 0; i < arr.length; i++) {
            if (o.equals(arr[i])) {
                return i;
            }
        }
        return -1;
    }

    public int lastIndexOf(T o) {
        for (int i = arr.length - 1; i >= 0; i--) {
            if (o.equals(arr[i])) {
                return i;
            }
        }
        return -1;
    }

    public boolean  remove(T o) {
        int result[] = new int[arr.length];
        int b = arr.length;
        int j = 0;
        for (int i = 0; i < arr.length - 1; i++) {
            if(arr[i]!=null)
                if(arr[i].equals(o)){
                    result[j] = i+1;
                    j++;
                }
        }
        for(int i=0;result[i]!=0;i++)
            arr[result[i]-1] = null;
        //b--;
        return true;

    }
    public String toString(){
        StringBuffer result = new StringBuffer("[");
        for (int i = 0; i < arr.length; i++) {
            result.append(arr[i]);
            if (i < arr.length -1) {
                result.append(", ");
            }
        }
        return result.toString() + "]";
    }
    /*public String toString(){
        Object []data2 = new Object[math];
        for(int i  = 0;i<size;i++){
            System.out.println(data[i] + "");
        }
        return "{"+ data.toString() + "}";
    }*/
}

